package com.doge.service.admin.collect;

import com.doge.bean.base.BaseData;
import com.doge.bean.base.BaseParam;
import com.doge.bean.pojo.collect.Collect;
import com.doge.bean.pojo.collect.CollectExample;
import com.doge.mapper.CollectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project2-wechat-mall
 * @description: 会员收藏接口的实现类
 * @author: zhu lei
 * @create: 2021-11-30 15:49
 **/
@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    CollectMapper collectMapper;
    @Override
    public BaseData collectList(Integer userId, Integer valueId, BaseParam baseParam) {
        PageHelper.startPage(baseParam.getPage(), baseParam.getLimit());
        CollectExample collectExample = new CollectExample();
        CollectExample.Criteria criteria = collectExample.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }
        collectExample.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());
        List<Collect> collects = collectMapper.selectByExample(collectExample);

        PageInfo<Collect> collectPageInfo = new PageInfo<>(collects);
        long toTal = collectPageInfo.getTotal();
        return BaseData.list(collects,toTal);
    }
}